
var util = require('../../utils/util.js')
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sou:"",
    carouselUrl:'',
    soustyle:"width:70%;margin-left:31%;padding-left: 37px;",
    isHide: false,
    AuthorizedLogin: '授权登录',
    UserPhone: '手机号授权',
    lee: "",
    flag: true,
    userInfo: {},
    shequ_xx:"shequ_xx",
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    statusBarHeight: getApp().globalData.statusBarHeight,
    statusBarHeight1: getApp().globalData.statusBarHeight1,
    swiperH:'',
    knowledgeList:'',//业务知识专栏列表
    nowIdx:0,//当前swiper索引
    indicatorDots: true, //小点
    indicatorColor: "white", //指示点颜色
    activeColor: "coral", //当前选中的指示点颜色
    autoplay: true, //是否自动轮播
    interval: 3000, //间隔时间
    duration: 1000, //滑动时间
  },
  Failure:function(e){
    if(wx.getStorageSync('token')){
      wx.navigateTo({
        url: '../Failure/Failure',
      })
    }else{
      this.getUserInfo()
    }
  },
  mall(){
      wx.navigateTo({
        url: '../mall/mall',
      })
  },
  otherFunc(){
    if(wx.getStorageSync('token')){
      wx.navigateTo({
        url: '../otherFunc/otherFunc',
      })
    }else{
      this.getUserInfo()
    }
  },
  tophone: function(el) {
    let phone = el.currentTarget.dataset.phone;
    // console.log(phone)
    wx.makePhoneCall({
        phoneNumber: phone,
        success: function() {
            console.log('成功拨打电话')
        }
    })
  },
  onLoad: function (options) {
    var that = this;
    // 获取轮播图
    wx.request({
      url: app.globalData.url_l + 'applets_login/index',
      method:"POST",
      success(res){
        console.log(res)
        that.setData({
          carouselUrl:res.data.data.banner
        })
      }
    }) 
    // 获取业务知识列表
    wx.request({
      url: app.globalData.url_l + 'applets_login/knowledge',
      method:"POST",
      success(res){
        console.log(res.data.data.data)
        that.setData({
          knowledgeList:res.data.data.data
        })
      }
    }) 
  },
    //获取swiper高度
getHeight:function(e){
  var winWid = wx.getSystemInfoSync().windowWidth - 2*50;//获取当前屏幕的宽度
  var imgh = e.detail.height;//图片高度
  var imgw = e.detail.width;
  var sH = parseInt(winWid * imgh / imgw )+ "px"
  this.setData({
    swiperH: sH
    //设置高度
  })
},
  //swiper滑动事件
  swiperChange:function(e){
    this.setData({
      nowIdx: e.detail.current
    })
  },
  // 获取用户登录授权
  getUserInfo(){
    this.setData({
      isHide:true
    })
  },

  bindGetUserInfo(e){
    if(e.detail){
      var that = this;
      var code = ''
      let user = e.detail.userInfo;
      var userinfo = {
        nickName:user.nickName,
        gender:user.gender,
        avatarUrl:user.avatarUrl,
        country:user.country,
        province:user.province,
        city:user.city
      }
       wx.login({
         success(res){
          wx.request({
            url: app.globalData.url_l+'applets_login/onLogin?user_info='+JSON.stringify(userinfo)+'&code='+res.code,
            method:'POST',
            header: {
             'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
            },
            success(suc){
              console.log(suc)
              wx.setStorageSync('token', suc.data.data.token)
            }          
          })       
          that.setData({
           isHide:false
         })
         }
       })
       
    }else{
      
    }
  },
  cancleGetUserInfo(){
    this.setData({
      isHide:false
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  onPullDownRefresh: function () {
   
   
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
   
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})